/************************************************************************/
/* GUI                                                                  */
/************************************************************************/
#include "GUI/TextMessages/GoldMessage.h"

namespace TD_GUI {

	/************************************************************************/
	/* ctors and dtors                                                      */
	/************************************************************************/
	GoldMessage::GoldMessage() : BaseTextMessage() {

	}

	GoldMessage::GoldMessage(const GoldMessage &rhs) : BaseTextMessage(rhs) {
		
	}

	GoldMessage & GoldMessage::operator =(const GoldMessage &rhs) {
		BaseTextMessage::operator =(rhs);
		m_text = rhs.getText();
		return(*this);
	}

	GoldMessage::GoldMessage(const Coord2D &textPos, const string &initString, const string &fontSource, 
		unsigned int fontSize, const Color &fontColor, renderType g_renderType) 
		: BaseTextMessage(textPos, initString, fontSource, fontSize, fontColor, g_renderType) {

		m_alphaChannel = m_fontColor.unused;
		m_originalPos = getPosition();
		m_dispVector.y = -2;
		m_upUnits = 15;
		m_finishedAnimation = false;
		m_fadedAnimation = false;
	}

	GoldMessage::~GoldMessage() {
		
	}

	/************************************************************************/
	/* Rendering                                                            */
	/************************************************************************/

	void GoldMessage::update() {
		if(!m_finishedAnimation) {
			m_position += m_dispVector;
			Coord2D tempPos = m_originalPos;
			tempPos.y -= m_upUnits;
			if(Coord2D::DistanceBetween(m_position, tempPos) < 2) {
				m_dispVector.y = 2; 
			} 
			if(Coord2D::DistanceBetween(m_position, m_originalPos) < 1 && m_dispVector.y == 2) {
				m_finishedAnimation = true;
			}
		} else {
			m_alphaChannel -= 4;
			if(m_alphaChannel <= 1) {
				m_alphaChannel = 1;
				m_fadedAnimation = true;
			}
		}
	}

	void GoldMessage::render(SDL_Surface *const g_destSurface, unsigned int deltaTime) {
		if(deltaTime != 0) 
			update();
		m_fontColor.unused = m_alphaChannel;
		setText(m_text);
		blitSurface(g_destSurface);
	}
}